/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef PLELF_SELECTION_HEADER_ENUMS_H
#define PLELF_SELECTION_HEADER_ENUMS_H

#include <tools/PLFlags.h>
using namespace PLSDK;

namespace PLSDK {

/**
 * Enum values of the elf section header that are used in both 32 bit and 64 bit header.
 */
class PLELFSectionHeaderEnums {
public:
	/**
	 * Constructor.
	 */
	inline PLELFSectionHeaderEnums() {}
	/**
	 * Text table name.
	 */
	static const char *SHNamesTextTable;
	/**
	 * These sections hold read-only data that typically contribute to a non-writable segment
     * in the process image.
	 */
	static const char *SHNamesRoDataTable;
	/**
	 * These sections hold read-only data that typically contribute to a non-writable segment
     * in the process image.
	 */
	static const char *SHNamesRoData1Table;
	/**
	 * These sections hold initialized data that contribute to the program's memory image.
	 */
	static const char *SHNamesDataTable;
	/**
	 * These sections hold initialized data that contribute to the program's memory image.
	 */
	static const char *SHNamesData1Table;
	/**
	 * This section holds uninitialized data that contribute to the program's memory image.
     * By definition, the system initializes the data with zeros when the program begins to run.
     * The section occupies no file space, as indicated by the section type, SHT_NOBITS.
	 */
	static const char *SHNamesBssTable;
	/**
	 * Symbol table name.
     * If the file has a loadable segment that includes the symbol table, the section's attributes
     * will include the SHF_ALLOC bit; otherwise, that bit will be off.
	 */
	static const char *SHNamesSymbolTable;
	/**
	 * This section holds the special symbol table section index array, as described above. The
     * section's attributes will include the SHF_ALLOC bit if the associated symbol table section
     * does; otherwise that bit will be off.
	 */
	static const char *SHNamesSymbolTableIndexArray;
	/**
	 * String table.
	 */
	static const char *SHNamesStringTable;
	/**
	 * Section Header String table.
	 */
	static const char *SHNamesSectionHeaderStringTable;
    /**
     * This section holds version control information.
     */
    static const char *SHNamesCommentTable;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugAbbrev;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugInfo;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugLine;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugLoc;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugPubNames;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugAranges;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugString;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugMacInfo;
    /**
     * This section holds information for symbolic debugging. The contents are unspecified. All
     * section names with the prefix .debug are reserved for future use in the ABI.
     */
    static const char *SHNamesDebugRanges;
    /**
     * This section holds dynamic linking information. The section's attributes will include the
     * SHF_ALLOC bit. Whether the SHF_WRITE bit is set is processor specific.
     */
    static const char *SHNamesDynamic;
    /**
     * This section holds strings needed for dynamic linking, most commonly the strings that
     * represent the names associated with symbol table entries.
     */
    static const char *SHNamesDynamicString;
    /**
     * This section holds the dynamic linking symbol table, as described in "Symbol Table".
     */
    static const char *SHNamesDynamicSymbol;
    /**
     * This section holds executable instructions that contribute to the process termination code.
     * That is, when a program exits normally, the system arranges to execute the code in this section.
     */
    static const char *SHNamesFini;
    /**
     * This section holds an array of function pointers that contributes to a single termination array
     * for the executable or shared object containing the section.
     */
    static const char *SHNamesFiniArray;
    /**
     * This section holds the global offset table.
     */
    static const char *SHNamesGlobalOffsetTable;
    /**
     * This section holds a symbol hash table.
     */
    static const char *SHNamesSymbolHashtable;
    /**
     * This section holds executable instructions that contribute to the process initialization code.
     * When a program starts to run, the system arranges to execute the code in this section before calling
     * the main program entry point (called main for C programs).
     */
    static const char *SHNamesInit;
    /**
     * This section holds an array of function pointers that contributes to a single initialization array
     * for the executable or shared object containing the section.
     */
    static const char *SHNamesInitArray;
    /**
     * This section holds the path name of a program interpreter. If the file has a loadable segment that
     * includes relocation, the sections' attributes will include the SHF_ALLOC bit; otherwise, that bit will be off.
     */
    static const char *SHNamesProgramInterpreter;
    /**
     * This section holds line number information for symbolic debugging, which describes the correspondence
     * between the source program and the machine code. The contents are unspecified.
     */
    static const char *SHNamesLineNumber;
    /**
     * This section holds information.
     */
    static const char *SHNamesNote;
    /**
     * This section holds the procedure linkage table.
     */
    static const char *SHNamesProcedureLinkageTable;
    /**
     * This section holds an array of function pointers that contributes to a single pre-initialization array
     * for the executable or shared object containing the section.
     */
    static const char *SHNamesPreInit;
	/**
	 * Possable values for the section table type.
	 */
	enum SHType {
		/**
		 * This value marks the section header as inactive; it does not have an associated
		 * section. Other members of the section header have undefined values.
		 */
		SHTypeNull					= 0,
		/**
		 * The section holds information defined by the program, whose format and meaning
		 * are determined solely by the program.
		 */
		SHTypeProgBits				= 1,
		/**
		 * These sections hold a symbol table. Currently, an object file may have only one
		 * section of each type, but this restriction may be relaxed in the future. Typically,
		 * SHTypeSymbolTable provides symbols for link editing, though it may also be used
		 * for dynamic linking. As a complete symbol table, it may contain many symbols
		 * unnecessary for dynamic linking. Consequently, an object file may also contain a
		 * SHTypeDynamicSymbol section, which holds a minimal set of dynamic linking symbols,
		 * to save space.
		 */
		SHTypeSymbolTable			= 2,
		/**
		 * The section holds a string table. An object file may have multiple string table sections.
		 */
		SHTypeStringTable			= 3,
		/**
		 * The section holds relocation entries with explicit addends, such as type Elf32_Rela for
		 * the 32-bit class of object files or type Elf64_Rela for the 64-bit class of object files.
		 * An object file may have multiple relocation sections.
		 */
		SHTypeRelocationA			= 4,
		/**
		 * The section holds a symbol hash table. Currently, an object file may have only one hash
		 * table, but this restriction may be relaxed in the future.
		 */
		SHTypeHash					= 5,
		/**
		 * The section holds information for dynamic linking. Currently, an object file may have
		 * only one dynamic section, but this restriction may be relaxed in the future.
		 */
		SHTypeDynamic				= 6,
		/**
		 * The section holds information that marks the file in some way.
		 */
		SHTypeNote					= 7,
		/**
		 * A section of this type occupies no space in the file but otherwise resembles SHTypeProgBits.
		 * Although this section contains no bytes, the sh_offset member contains the conceptual file offset.
		 */
		SHTypeNoBits				= 8,
		/**
		 * The section holds relocation entries without explicit addends, such as type Elf32_Rel for the
		 * 32-bit class of object files or type Elf64_Rel for the 64-bit class of object files. An object
		 * file may have multiple relocation sections.
		 */
		SHTypeRelocation			= 9,
		/**
		 * This section type is reserved but has unspecified semantics.
		 */
		SHTypeSHLib					= 10,
		/**
		 * These sections hold a symbol table. Currently, an object file may have only one
		 * section of each type, but this restriction may be relaxed in the future. Typically,
		 * SHTypeSymbolTable provides symbols for link editing, though it may also be used
		 * for dynamic linking. As a complete symbol table, it may contain many symbols
		 * unnecessary for dynamic linking. Consequently, an object file may also contain a
		 * SHTypeDynamicSymbol section, which holds a minimal set of dynamic linking symbols,
		 * to save space.
		 */
		SHTypeDynamicSymbol         = 11,
		/**
		 * This section contains an array of pointers to initialization functions.
		 * Each pointer in the array is taken as a parameterless procedure with a void return.
		 */
		SHTypeInitArray             = 14,
		/**
		 * This section contains an array of pointers to termination functions.
		 * Each pointer in the array is taken as a parameterless procedure with a void return.
		 */
		SHTypeFinishArray			= 15,
		/**
		 * This section contains an array of pointers to functions that are invoked before all other
		 * initialization functions.
		 * Each pointer in the array is taken as a parameterless procedure with a void return.
		 */
		SHTypePreInitArray          = 16,
		/** 
		 * This section defines a section group. A section group is a set of sections that are related
		 * and that must be treated specially by the linker. The section header table entry for a group
		 * section must appear in the section header table before the entries for any of the sections
		 * that are members of the group.
		 */
		SHTypeGroup					= 17,
		/**
		 * This section is associated with a section of type SHT_SYMTAB and is required if any of the
		 * section header indexes referenced by that symbol table contain the escape value SHN_XINDEX.
		 * The section is an array of Elf32_Word values. Each value corresponds one to one with a symbol
		 * table entry and appear in the same order as those entries. The values represent the section 
		 * header indexes against which the symbol table entries are defined.
		 */
		SHTypeSymbolTableIndex      = 18,
		/**
		 * Values in this inclusive range are reserved for operating system-specific semantics.
		 * SHTypeLoos - SHTypeHIOS.
		 */
		SHTypeLoos					= 0x60000000,
		/**
		 * Values in this inclusive range are reserved for operating system-specific semantics.
		 * SHTypeLoos - SHTypeHIOS.
		 */
		SHTypeHIOS					= 0x6fffffff,
		/**
		 * Values in this inclusive range are reserved for processor-specific semantics.
		 * SHTypeLoProc - SHTypeHiProc.
		 */
		SHTypeLoProc				= 0x70000000,
		/**
		 * Values in this inclusive range are reserved for processor-specific semantics.
		 * SHTypeLoProc - SHTypeHiProc.
		 */
		SHTypeHiProc				= 0x7fffffff,
		/**
		 * This value specifies the lower bound of the range of indexes reserved for application programs.
		 */
		SHTypeLoUser				= 0x80000000,
		/**
		 * This value specifies the upper bound of the range of indexes reserved for application programs.
		 * Section types between SHTypeLoUser and SHTypeHiUser may be used by the application, without conflicting
		 * with current or future system-defined section types.
		 */
		SHTypeHiUser				= 0xffffffff
	};
	/**
	 * A section header's sh_flags member holds 1-bit flags that describe the section's attributes.
	 * Defined values appear in the following table; other values are reserved.
	 */
	enum SHFlag {
		/**
		 * The section contains data that should be writable during process execution.
		 */
		SHFlagsWrite				= 0x1,
		/**
		 * The section occupies memory during process execution. Some control sections do not reside in the
		 * memory image of an object file; this attribute is off for those sections.
		 */
		SHFlagsAlloc				= 0x2,
		/**
		 * The section contains executable machine instructions.
		 */
		SHFlagsExecInstructions     = 0x4,
		/**
		 * The data in the section may be merged to eliminate duplication. Unless the SHFlagsStrings flag is also set,
		 * the data elements in the section are of a uniform size. The size of each element is specified in the section
		 * header's sh_entsize field. If the SHFlagsStrings flag is also set, the data elements consist of
		 * null-terminated character strings. The size of each character is specified in the section header's sh_entsize field.
		 * Each element in the section is compared against other elements in sections with the same name, type and flags.
		 * Elements that would have identical values at program run-time may be merged. Relocations referencing elements
		 * of such sections must be resolved to the merged locations of the referenced values. Note that any relocatable
		 * values, including values that would result in run-time relocations, must be analyzed to determine whether the
		 * run-time values would actually be identical. An ABI-conforming object file may not depend on specific elements
		 * being merged, and an ABI-conforming link editor may choose not to merge specific elements.
		 */
		SHFlagsMerged				= 0x10,
		/**
		 * The data elements in the section consist of null-terminated character strings. The size of each character is
		 * specified in the section header's sh_entsize field.
		 */
		SHFlagsStrings				= 0x20,
		/**
		 * The sh_info field of this section header holds a section header table index.
		 */
		SHFlagsInfoLink             = 0x40,
		/**
		 * This flag adds special ordering requirements for link editors. The requirements apply if the sh_link field of
		 * this section's header references another section (the linked-to section). If this section is combined with other
		 * sections in the output file, it must appear in the same relative order with respect to those sections, as the
		 * linked-to section appears with respect to sections the linked-to section is combined with.
		 */
		SHFlagsLinkOrder			= 0x80,
		/**
		 * This section requires special OS-specific processing to avoid incorrect behavior. If this section has either an
		 * sh_type value or contains sh_flags bits in the OS-specific ranges for those fields, and a link editor processing
		 * this section does not recognize those values, then the link editor should reject the object file containing this
		 * section with an error.
		 */
		SHFlagsOSNonConforming      = 0x100,
		/**
		 * This section is a member (perhaps the only one) of a section group. The section must be referenced by a section of
		 * type SHTypeGroup. The SHTypeGroup flag may be set only for sections contained in relocatable objects (objects with
		 * the ELF header e_type member set to SHTypeRelocation)
		 */
		SHFlagsGroup				= 0x200,
		/**
		 * All bits included in this mask are reserved for operating system-specific semantics.
		 */
		SHFlagsMaskOS				= 0x0ff00000,
		/**
		 * All bits included in this mask are reserved for processor-specific semantics. If meanings are specified, the processor
		 * supplement explains them.
		 */
		SHFlagsMaskProcessor		= 0xf0000000
	};
	PLDECLAREFLAGS(SHFlags, SHFlag);
	/**
	 * Group flags.
	 */
	enum SHGroup {
		/**
		 * This is a COMDAT group. It may duplicate another COMDAT group in another object file, where duplication is defined as
		 * having the same group signature. In such cases, only one of the duplicate groups may be retained by the linker, and
		 * the members of the remaining groups must be discarded.
		 */
		SHGroupCOMDATA				= 0x1
	};
	PLDECLAREFLAGS(SHGroups, SHGroup);
};

}

#endif
